<template>
	<!-- 该页面是工地招工/除了发布招工的其他定位地址的地址【 -->
  <view class="content">
    <view class="regiona-box">
      <view class="regiona-right" @click="onClickRegion">
        <view v-if="city" class="regiona">
          {{ city }}
        </view>
		
		<view v-else class="regiona">
          全国
        </view>
      </view>
    </view>

    <!-- <regionalComponents
      v-show="regionaStatus"
      ref="region"
      @cancel="cancel"
      @sure="sure"
    /> -->
	<!--组件 lotus-address:实现位置功能 ，省市区三级联动-->
	<lotus-address @choseVal="choseValue" :lotusAddressData="lotusAddressData"></lotus-address>

  </view>
</template>

<script>
	import lotusAddress from "./Winglau14-lotusAddress/Winglau14-lotusAddress.vue";
// import regionalComponents from "./regionalComponents.vue";
import { mapGetters, mapMutations } from "vuex";
export default {
	
  components: {
    // regionalComponents,
	// 工地招工/地址中的国市区的数据在lotusAddress组件中
	lotusAddress
  },
  computed: {
	  // getters辅助函数
    ...mapGetters(["city"]),
  },
  data() {
    return {
      regionaStatus: false,
      regiona: "",
	  lotusAddressData:{
	      visible:false,
	      provinceName:'',
	      cityName:'',
	      townName:'',
	  },
    };
  },
  // onLoad:监听页面的加载
  onLoad() {
    setTimeout(() => {
      this.$refs.region.getScreen();
    }, 1000);
  },

  methods: {
    ...mapMutations(["setCity", "setCitiesInfor"]),
    onClickRegion() {
		this.$emit('fnscroll',false)
      // this.regionaStatus = true;
	  this.lotusAddressData.visible = true;
	  this.lotusAddressData.provinceName = '';
	  this.lotusAddressData.cityName = '';
	  this.lotusAddressData.townName = '';
    },
   /* cancel() {
    
      this.regionaStatus = false;

      // this.$emit("fnpickerAddress", {
      //   status: false,
      // });
    }, */
    sure(data) {
      if (data) {
		  
		  console.log(data,'99999994')
       
        this.setCity(data[2]);
        this.setCitiesInfor(data);
        this.regionaStatus = false;
        this.$emit("fnpickerAddress", {
          status: false,
          loadDate: true,
        });
      }
    },
	choseValue(res){
	    //res数据源包括已选省市区与省市区code
		let {province,city,town} = res;
		// 自定义事件，子传父
		this.$emit('fnscroll',!res.visible)
		this.lotusAddressData.visible = res.visible;
		if(town){
			this.setCity(town);
		}else if(city){
			this.setCity(city);
		}else if(province){
			this.setCity(province);
		}else{
			this.setCity('全国');
		}
		
		console.log(res,'99999995')
		console.log(province,city,town,'99999996')		
		
			
		this.setCitiesInfor([province,city,town]);
			
		this.$emit("fnpickerAddress", {
			  status: false,
			  loadDate: true,
			});
	}
  },
};
</script>

<style lang="scss" scoped>
.regiona-right {
  .regiona {
    flex: 1;
    font-size: 25upx;
    font-weight: 400;
    color: #333333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .regiona-txt-none {
    flex: 1;
    font-size: 25upx;
    font-weight: 400;
    color: #9ca5aa;
  }
}
</style>
